package com.example.community.controller;

import com.example.community.DTO.addComment;
import com.example.community.entity.comment;
import com.example.community.service.impl.commentImpl;
import com.example.community.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class commentController {
    @Autowired
    private com.example.community.service.impl.commentImpl commentImpl;
    //通过传入文章Id来获取该文章下的所有评论
    @GetMapping("/getComment/{id}")
    public Result<List<comment>> getOneByArticleId(@PathVariable String id){
        List<comment> comments = commentImpl.queryOneByArticleId(id);
        return Result.success(comments,"成功获取该文章的所有评论");
    }

    @PostMapping("/addComment")
    public Result<String> addComment(@RequestBody addComment addComment){
        String s = commentImpl.addOne(addComment);
        return Result.success(s,"评论成功");
    }
//    删除文章中单个评论
    @GetMapping("/deleteComment/{id}")
    public Result<String> deleteComment(@PathVariable String id){
        commentImpl.deleteOne(id);
        return Result.success("","成功删除ID为"+id+"的评论");
    }
}
